from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-10-04 14:13:12.132847
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 04, Oct, 2021
Time: 14:13:17
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.5118
Nobs: 434.000 HQIC: -47.0230
Log likelihood: 4823.97 FPE: 2.71274e-21
AIC: -47.3564 Det(Omega_mle): 2.20988e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.429660 0.091084 4.717 0.000
L1.Burgenland 0.104287 0.047095 2.214 0.027
L1.Kärnten -0.112933 0.023691 -4.767 0.000
L1.Niederösterreich 0.151033 0.100973 1.496 0.135
L1.Oberösterreich 0.115102 0.099362 1.158 0.247
L1.Salzburg 0.286600 0.049718 5.765 0.000
L1.Steiermark 0.034982 0.065945 0.530 0.596
L1.Tirol 0.105022 0.052205 2.012 0.044
L1.Vorarlberg -0.101447 0.046828 -2.166 0.030
L1.Wien -0.005815 0.090579 -0.064 0.949
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.013608 0.207695 0.066 0.948
L1.Burgenland -0.050095 0.107388 -0.466 0.641
L1.Kärnten 0.037954 0.054021 0.703 0.482
L1.Niederösterreich -0.210562 0.230244 -0.915 0.360
L1.Oberösterreich 0.494838 0.226571 2.184 0.029
L1.Salzburg 0.305460 0.113369 2.694 0.007
L1.Steiermark 0.104451 0.150372 0.695 0.487
L1.Tirol 0.310529 0.119042 2.609 0.009
L1.Vorarlberg 0.000299 0.106779 0.003 0.998
L1.Wien 0.005352 0.206544 0.026 0.979
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.243127 0.046182 5.265 0.000
L1.Burgenland 0.088513 0.023878 3.707 0.000
L1.Kärnten -0.003361 0.012012 -0.280 0.780
L1.Niederösterreich 0.208618 0.051196 4.075 0.000
L1.Oberösterreich 0.156329 0.050379 3.103 0.002
L1.Salzburg 0.039017 0.025208 1.548 0.122
L1.Steiermark 0.023695 0.033436 0.709 0.479
L1.Tirol 0.066872 0.026469 2.526 0.012
L1.Vorarlberg 0.061235 0.023743 2.579 0.010
L1.Wien 0.117198 0.045926 2.552 0.011
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186480 0.044944 4.149 0.000
L1.Burgenland 0.045781 0.023238 1.970 0.049
L1.Kärnten -0.006337 0.011690 -0.542 0.588
L1.Niederösterreich 0.142410 0.049824 2.858 0.004
L1.Oberösterreich 0.318500 0.049029 6.496 0.000
L1.Salzburg 0.100163 0.024532 4.083 0.000
L1.Steiermark 0.128351 0.032540 3.944 0.000
L1.Tirol 0.076858 0.025760 2.984 0.003
L1.Vorarlberg 0.056362 0.023106 2.439 0.015
L1.Wien -0.048623 0.044695 -1.088 0.277
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.207922 0.089226 2.330 0.020
L1.Burgenland -0.048893 0.046134 -1.060 0.289
L1.Kärnten -0.033012 0.023207 -1.422 0.155
L1.Niederösterreich 0.114164 0.098913 1.154 0.248
L1.Oberösterreich 0.172851 0.097335 1.776 0.076
L1.Salzburg 0.251289 0.048703 5.160 0.000
L1.Steiermark 0.077096 0.064600 1.193 0.233
L1.Tirol 0.122294 0.051140 2.391 0.017
L1.Vorarlberg 0.115089 0.045872 2.509 0.012
L1.Wien 0.025277 0.088731 0.285 0.776
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.038293 0.069049 0.555 0.579
L1.Burgenland 0.023418 0.035701 0.656 0.512
L1.Kärnten 0.054662 0.017959 3.044 0.002
L1.Niederösterreich 0.203084 0.076545 2.653 0.008
L1.Oberösterreich 0.335426 0.075324 4.453 0.000
L1.Salzburg 0.047840 0.037690 1.269 0.204
L1.Steiermark -0.004217 0.049992 -0.084 0.933
L1.Tirol 0.112020 0.039576 2.831 0.005
L1.Vorarlberg 0.068571 0.035499 1.932 0.053
L1.Wien 0.122433 0.068666 1.783 0.075
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197687 0.084504 2.339 0.019
L1.Burgenland 0.013345 0.043692 0.305 0.760
L1.Kärnten -0.057354 0.021979 -2.609 0.009
L1.Niederösterreich -0.127526 0.093678 -1.361 0.173
L1.Oberösterreich 0.195854 0.092184 2.125 0.034
L1.Salzburg 0.036166 0.046126 0.784 0.433
L1.Steiermark 0.285605 0.061181 4.668 0.000
L1.Tirol 0.489081 0.048434 10.098 0.000
L1.Vorarlberg 0.077242 0.043445 1.778 0.075
L1.Wien -0.107593 0.084035 -1.280 0.200
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156578 0.092130 1.700 0.089
L1.Burgenland -0.012411 0.047635 -0.261 0.794
L1.Kärnten 0.063557 0.023963 2.652 0.008
L1.Niederösterreich 0.196215 0.102132 1.921 0.055
L1.Oberösterreich -0.124026 0.100503 -1.234 0.217
L1.Salzburg 0.233321 0.050288 4.640 0.000
L1.Steiermark 0.149501 0.066703 2.241 0.025
L1.Tirol 0.047620 0.052805 0.902 0.367
L1.Vorarlberg 0.130214 0.047365 2.749 0.006
L1.Wien 0.161407 0.091619 1.762 0.078
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.479920 0.050088 9.581 0.000
L1.Burgenland -0.007894 0.025898 -0.305 0.761
L1.Kärnten -0.009565 0.013028 -0.734 0.463
L1.Niederösterreich 0.204919 0.055526 3.690 0.000
L1.Oberösterreich 0.252442 0.054641 4.620 0.000
L1.Salzburg 0.024258 0.027340 0.887 0.375
L1.Steiermark -0.021920 0.036264 -0.604 0.546
L1.Tirol 0.065941 0.028708 2.297 0.022
L1.Vorarlberg 0.060883 0.025751 2.364 0.018
L1.Wien -0.046669 0.049811 -0.937 0.349
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.020180 0.081352 0.138630 0.131447 0.046980 0.075476 -0.002810 0.187735
Kärnten 0.020180 1.000000 -0.041957 0.130349 0.048654 0.071355 0.452100 -0.089611 0.089176
Niederösterreich 0.081352 -0.041957 1.000000 0.283709 0.082807 0.266185 0.033923 0.136536 0.263349
Oberösterreich 0.138630 0.130349 0.283709 1.000000 0.176712 0.287710 0.158488 0.100881 0.135413
Salzburg 0.131447 0.048654 0.082807 0.176712 1.000000 0.126230 0.057234 0.106670 0.049328
Steiermark 0.046980 0.071355 0.266185 0.287710 0.126230 1.000000 0.131720 0.090194 -0.014776
Tirol 0.075476 0.452100 0.033923 0.158488 0.057234 0.131720 1.000000 0.049859 0.121544
Vorarlberg -0.002810 -0.089611 0.136536 0.100881 0.106670 0.090194 0.049859 1.000000 -0.046893
Wien 0.187735 0.089176 0.263349 0.135413 0.049328 -0.014776 0.121544 -0.046893 1.000000